@import './theme/default';
@import './theme/font';
@import './mixins/popup';

$option-height: 32px;
$select-width-xs: $default-form-width-xs;
$select-width-s: $default-form-width-s;
$select-width-m: $default-form-width-m;
$select-width-l: $default-form-width-l;
$select-width-xl: $default-form-width-xl;

@mixin ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@mixin placeholder {
  @include theme-color(color, stroke, 4);
  @include ellipsis;
}

@mixin tag-style {
  @include theme-color(border-color, stroke, 5);
  border-radius: 2px;
  height: 18px;
  margin: 2px 4px 2px 0;
  padding-left: 4px;
  line-height: 16px;
  font-size: $font-size-small;
  display: flex;
  align-items: center;
  word-break: break-all;
  box-sizing: border-box;
  overflow: hidden;
  &-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.zent-select-v2 {
  @include theme-color(border-color, stroke, 5);
  @include theme-color(background-color, stroke, 9);
  border-width: 1px;
  border-style: solid;
  border-radius: 2px;
  cursor: pointer;
  min-height: 32px;
  padding: 5px 26px 5px 12px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  transition: border-color 0.25s;
  outline: none;
  position: relative;
  line-height: 20px;

  &-xs {
    width: $select-width-xs;
  }

  &-s {
    width: $select-width-s;
  }

  &-m {
    width: $select-width-m;
  }

  &-l {
    width: $select-width-l;
  }

  &-xl {
    width: $select-width-xl;
  }

  .zenticon-down {
    @include theme-color(color, stroke, 2);
    font-size: 20px;
    right: 8px;
    position: absolute;
    transition: transform 0.25s;
    top: 5px;
    margin: auto;
  }

  &.zent-select-v2-disabled {
    @include theme-color(color, stroke, 5);
    @include theme-color(border-color, stroke, 5);
    @include theme-color(background-color, stroke, 8);
    cursor: not-allowed;
    user-select: none;

    &:hover {
      @include theme-color(color, stroke, 5);
      @include theme-color(border-color, stroke, 5);
      @include theme-color(background-color, stroke, 8);
      box-shadow: none;
    }

    .zent-select-v2-tag {
      @include theme-color(color, stroke, 5);
      @include theme-color(border-color, stroke, 5);
      @include theme-color(background-color, stroke, 8);
      cursor: not-allowed;
    }

    .zent-select-v2-tag-close {
      @include theme-color(color, stroke, 5);
      cursor: not-allowed;
    }

    .zent-select-v2-tag-collapsed-trigger {
      @include theme-color(color, stroke, 5);
      @include theme-color(background-color, stroke, 6);
    }

    .zenticon-down {
      @include theme-color(color, stroke, 4);
    }
  }

  &-multiple {
    padding-top: 4px;
    padding-bottom: 4px;

    .zent-select-v2-placeholder {
      line-height: 22px;
    }
    .zent-select-v2-search {
      min-height: 22px;
      line-height: 22px;
    }
  }

  &-placeholder {
    @include placeholder;
  }

  &-text {
    @include ellipsis;
  }

  &-clearable {
    .zenticon-close-circle {
      @include theme-color(color, stroke, 4);
      font-size: 20px;
      position: absolute;
      right: 8px;
      top: 5px;
      margin: auto;
      display: none;
      cursor: pointer;
    }

    &.zent-select-v2:hover,
    &.zent-select-v2-active {
      .zenticon-down {
        display: none;
      }

      .zenticon-close-circle {
        display: inline-block;
      }
    }
  }

  &:hover,
  &.zent-select-v2-active {
    @include theme-color(border-color, primary, 4);
  }

  &.zent-select-v2-inline {
    display: inline-flex;
  }

  &-collapsable {
    &-single {
      display: flex;
      flex-wrap: nowrap;
      .zent-select-v2-tag-collapsed-trigger {
        flex-shrink: 0;
      }
    }

    .zent-select-v2-search-wrap {
      flex: 1;
    }
  }

  &-search {
    outline: none;
    border: 0;
    margin: 0;
    padding: 0;
    width: 100%;

    &::placeholder {
      @include placeholder;
    }

    &-wrap {
      width: 100%;
      position: relative;

      &-auto-width {
        width: auto;
        min-width: 10px;
        min-height: 20px;
      }

      .zent-select-v2-search {
        min-width: 10px;
        position: absolute;
        top: 0;
        left: 0;
      }
    }

    &-mirror {
      white-space: nowrap;
      visibility: hidden;
    }
  }

  &-popup {
    @include popup;
    max-height: 8.5 * $option-height;
    overflow-y: auto;

    &-empty {
      @include theme-color(color, stroke, 3);
      padding: 0 20px;
      min-height: 48px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    &-loading {
      font-size: 12px;
      text-align: center;
      padding: 7px 0;
    }
  }

  &-option {
    height: $option-height;
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 6px 12px;

    &-text {
      @include ellipsis;
      display: flex;
      align-items: center;
      flex: 1 1 100%;

      &-content {
        @include ellipsis;
      }

      &-highlight {
        @include theme-color(color, primary, 4);
      }
    }

    &:hover,
    &-active,
    &-active.zent-select-v2-option-selected {
      @include theme-color(background-color, stroke, 8);
    }

    &-header {
      @include theme-color(color, stroke, 2);
      cursor: default;
      font-size: $font-size-small;
      padding: 8px 12px;
      line-height: 16px;

      &:first-child {
        margin-top: 8px;
      }

      &:hover,
      &.zent-select-v2-option-active {
        @include theme-color(background-color, stroke, 9);
        cursor: default;
      }
    }

    &-disabled {
      @include theme-color(color, stroke, 4);
      cursor: not-allowed;

      &:hover,
      &.zent-select-v2-option-active {
        @include theme-color(background-color, stroke, 9);
        cursor: not-allowed;
      }
    }

    &-selected {
      @include theme-color(background-color, primary, 8);
      font-weight: $font-weight-medium;

      &-bold {
        font-weight: $font-weight-medium;
      }

      &-multiple {
        @include theme-color(color, stroke, 3);
        font-size: 18px;
        display: block;
        margin-left: auto;
        margin-right: -4px; // align with clear/open/close icon
        padding-left: 8px;
      }
    }

    &-loading {
      margin-left: auto;
      padding-left: 8px;
    }
  }

  &-tag {
    @include theme-color(border-color, stroke, 5);
    @include tag-style;
    border-width: 1px;
    border-style: solid;
    cursor: default;

    &-close {
      @include theme-color(color, stroke, 3);
      cursor: pointer;
      font-size: 16px;
    }
  }

  &-tag-collapsed {
    &-trigger {
      @include theme-color(background-color, stroke, 7);
      @include tag-style;
      padding: 0 4px;
      cursor: pointer;
      justify-content: center;
    }

    &-content {
      @include font-normal;
      max-width: 216px;
      max-height: 80px;
      overflow-y: auto;
      word-break: break-all;
      @include theme-color(border-color, stroke, 4);
    }
  }
}
